package com.example.demo.vec;

import com.huaban.analysis.jieba.JiebaSegmenter;
import com.huaban.analysis.jieba.SegToken;
import com.huaban.analysis.jieba.WordDictionary;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.ansj.recognition.impl.StopRecognition;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class Segment {

    public static List<Term> Seg(String sentence){
        StopRecognition stopRecognition=new StopRecognition();
        stopRecognition.insertStopWords(",", " ", ".", "，", "。", ":", "：", "'", "‘", "’", "　", "“", "”", "《", "》", "[", "]", "-");

    //    WordDictionary.getInstance().loadUserDict(Paths.get("E:\\Anacode\\disease_name.txt"));
     //   JiebaSegmenter jiebaSegmenter=new JiebaSegmenter();

       // return jiebaSegmenter.process(sentence, JiebaSegmenter.SegMode.INDEX);
        return ToAnalysis.parse(sentence).recognition(stopRecognition).getTerms();


    }
    public static List<SegToken> jieba(String sentence){
           JiebaSegmenter jiebaSegmenter=new JiebaSegmenter();
         return jiebaSegmenter.process(sentence, JiebaSegmenter.SegMode.INDEX);
    }


    public static List<String> getwords2(String sentence){

        List<Term> terms=Seg(sentence);
        List<String> wordlist=new ArrayList<>();
        for(Term term:terms){
            wordlist.add(term.getName());
        }


        return wordlist;
    }
    public static List<String> getwords(String sentence){

        List<SegToken> terms=jieba(sentence);
        List<String> wordlist=new ArrayList<>();
        for(SegToken term:terms){
            wordlist.add(term.word);
        }
        return wordlist;
    }
}
